#!/bin/bash

echo "=== Jeecg Boot 配置切换工具 ==="
echo ""

echo "请选择配置模式："
echo "1. 完全本地化 (推荐开发使用)"
echo "2. 混合模式 (线上MySQL + 禁用本地缓存) - 当前配置"
echo "3. 完全线上化 (所有服务都使用线上)"
echo "4. 查看当前配置"
echo ""

read -p "请输入选项 (1-4): " choice

case $choice in
    1)
        echo "切换到完全本地化配置..."
        # 备份当前配置
        cp jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml.backup
        
        # 修改为本地配置
        sed -i '' 's/host: 119.29.117.249/host: localhost/g' jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
        sed -i '' 's/enabled: false/enabled: true/g' jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
        
        echo "✅ 已切换到完全本地化配置"
        echo "⚠️  请确保本地MySQL已安装并运行"
        echo "⚠️  请确保本地Redis和RabbitMQ已启动"
        ;;
    2)
        echo "切换到混合模式配置..."
        # 备份当前配置
        cp jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml.backup
        
        # 修改为混合配置
        sed -i '' 's/host: localhost/host: 119.29.117.249/g' jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
        sed -i '' 's/address: localhost:6379/address: 119.29.117.249:6379/g' jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
        sed -i '' 's/enabled: true/enabled: false/g' jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
        
        echo "✅ 已切换到混合模式配置"
        echo "⚠️  注意：Redis、RabbitMQ、Redisson已禁用，避免数据不一致"
        ;;
    3)
        echo "切换到完全线上化配置..."
        # 备份当前配置
        cp jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml.backup
        
        # 修改为线上配置
        sed -i '' 's/host: localhost/host: 119.29.117.249/g' jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
        sed -i '' 's/address: localhost:6379/address: 119.29.117.249:6379/g' jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
        sed -i '' 's/enabled: false/enabled: true/g' jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
        
        echo "✅ 已切换到完全线上化配置"
        echo "⚠️  请确保线上Redis和RabbitMQ服务可用"
        ;;
    4)
        echo "当前配置信息："
        echo ""
        echo "数据库连接："
        grep -A 2 "url:" jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml | head -3
        echo ""
        echo "Redis配置："
        grep -A 3 "redis:" jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml | head -4
        echo ""
        echo "RabbitMQ配置："
        grep -A 3 "rabbitmq:" jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml | head -4
        echo ""
        echo "Redisson配置："
        grep -A 3 "redisson:" jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml | head -4
        ;;
    *)
        echo "❌ 无效选项，请重新运行脚本"
        exit 1
        ;;
esac

echo ""
echo "配置切换完成！"
echo "如需恢复配置，请运行："
echo "cp jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml.backup jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml" 